package com.hisysteTopet.hisystepet.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hisysteTopet.hisystepet.bean.Pet;
import com.hisysteTopet.hisystepet.mapper.provider.updatePetMessage;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PetMapper extends BaseMapper<Pet> {

    // 查询所有宠物
    @Select("select * from pet")
    public List<Pet> findAll();

    // 购物修改宠物的库存
    @Update("UPDATE pet SET pet_num = pet_num - #{petNumber} WHERE pet_id = #{petId}")
    public  void updateToPetNum(Integer petNumber,Integer petId);

    // 查询宠物的库存
    @Select(" SELECT * FROM pet WHERE pet.`pet_id` = #{petId} ")
    public Pet selectToPetId(Integer petId);

    // 修改宠物的信息
    @UpdateProvider(type = updatePetMessage.class, method = "updatePetMessage")
    public void updatePetMessage(Pet pet);

    // 删除宠物的信息
    @Delete("DELETE FROM pet WHERE pet_id = #{petId}")
    public void deletePetMessageById(String petId);

    // 管理员修改宠物的库存
    @Update("UPDATE pet SET pet.`pet_num` = #{petNumber} WHERE pet.`pet_id` = #{petId}")
    public  void updateToPetNumByAdmin(Integer petNumber,Integer petId);

    // 添加宠物
    @Insert("INSERT INTO pet(pet.`pet_name`,pet.`pet_variety`,pet.`pet_url`," +
            "pet.`pet_introduce`,pet.`pet_price`,pet.`pet_num`) " +
            " VALUE(#{petName},#{variety},#{url},#{introduce},#{price},#{num})")
    public  void insertPet(String petName,String variety,String url,
                           String introduce,Integer price,Integer num);
}
